<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://a42.vodafone.com/versions/all/v1.0"
    xmlns:tns="http://a42.vodafone.com/versions/all/v1.0"
    elementFormDefault="qualified"
>

    <!-- XML schema 1.0 legacy!!! -->

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    <!-- Definition of XML representations for purchase history resources and related DTOs. -->
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

    <!-- Import the common types for A42 resources. -->
    <xs:include schemaLocation="a42.xsd" />
    <!-- Import the referenced types for simple content catalog resources. -->
    <xs:include schemaLocation="sc2.xsd" />
    <!-- Import the referenced types for simple purchase API resources. -->
    <xs:include schemaLocation="spa.xsd" />

    <!-- Specific link types with defined link relation types. -->
    <xs:complexType name="PurchaseHistoriesLinkType">
        <xs:complexContent>
            <xs:restriction base="tns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/simplePurchaseHistory/purchaseHistories" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="PurchaseHistoryLinkType">
        <xs:complexContent>
            <xs:restriction base="tns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/simplePurchaseHistory/purchaseHistory" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="PurchasedItemsLinkType">
        <xs:complexContent>
            <xs:restriction base="tns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/simplePurchaseHistory/purchasedItems" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="PurchasedItemLinkType">
        <xs:complexContent>
            <xs:restriction base="tns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/simplePurchaseHistory/purchasedItem" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

    <!-- Representation for the service document for this API. -->
    <xs:element name="sphServiceDocument">
        <xs:complexType>
            <xs:sequence>
                <!-- Root link for all purchase histories only for admin authorization. -->
                <xs:element name="purchaseHistoriesRootLink" type="tns:PurchaseHistoriesLinkType" minOccurs="0" maxOccurs="1" />
                <!-- Root link for particular purchase history only for a provisioned user. -->
                <xs:element name="purchaseHistoryRootLink" type="tns:PurchaseHistoryLinkType" minOccurs="0" maxOccurs="1" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

    <!-- Representation for a collection resource that aggregates purchase history entities. -->
    <xs:element name="purchaseHistories" type="tns:PurchaseHistoriesType" />
    <xs:complexType name="PurchaseHistoriesType">
        <xs:complexContent>
            <xs:extension base="tns:PaginatableResourceType">
                <xs:sequence>
                    <!-- The actual collection of resource links. -->
                    <xs:element name="items" minOccurs="1" maxOccurs="1">
                        <xs:complexType>
                            <xs:choice>
                                <xs:sequence>
                                    <xs:element name="purchaseHistory" type="tns:PurchaseHistoryType" minOccurs="0" maxOccurs="unbounded" />
                                </xs:sequence>
                                <xs:sequence>
                                    <xs:element name="link" type="tns:PurchaseHistoryLinkType" minOccurs="0" maxOccurs="unbounded" />
                                </xs:sequence>
                            </xs:choice>
                        </xs:complexType>
                    </xs:element>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <!-- Representation for a collection resource that aggregates purchase history entities. -->
    <xs:element name="purchasedItems" type="tns:PurchasedItemsType" />
    <xs:complexType name="PurchasedItemsType">
        <xs:complexContent>
            <xs:extension base="tns:PaginatableResourceType">
                <xs:sequence>
                    <!-- The actual collection of resource links. -->
                    <xs:element name="items" minOccurs="1" maxOccurs="1">
                        <xs:complexType>
                            <xs:choice>
                                <xs:sequence>
                                    <xs:element name="purchasedItem" type="tns:PurchasedItemType" minOccurs="0" maxOccurs="unbounded" />
                                </xs:sequence>
                                <xs:sequence>
                                    <xs:element name="link" type="tns:PurchasedItemLinkType" minOccurs="0" maxOccurs="unbounded" />
                                </xs:sequence>
                            </xs:choice>
                        </xs:complexType>
                    </xs:element>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

    <!-- To create a new purchase history. This is not a resource, therefore no resourceIdentity element. -->
    <xs:element name="purchaseHistory" type="tns:PurchaseHistoryType" />
    <xs:complexType name="PurchaseHistoryType">
        <xs:complexContent>
            <xs:extension base="tns:ResourceType">
                <xs:sequence>
                    <!-- The actual collection of purchased item links. -->
                    <xs:choice minOccurs="0" maxOccurs="1">
                        <xs:element name="purchasedItemsLink" type="tns:PurchasedItemsLinkType" />
                        <xs:element name="purchasedItems" type="tns:PurchasedItemsType" />
                    </xs:choice>
                    <!-- The user that owns the purchase history / the purchased-items. -->
                    <xs:element name="userId" type="xs:string" minOccurs="0" maxOccurs="1" />
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <!-- To create a new purchased item. This is not a resource, therefore no resourceIdentity element. -->
    <xs:element name="purchasedItem" type="tns:PurchasedItemType" />
    <xs:complexType name="PurchasedItemType">
        <xs:complexContent>
            <xs:extension base="tns:ResourceType">
                <xs:sequence>
                    <!-- Link to the catalog-item that has been purchased. -->
                    <xs:choice minOccurs="0" maxOccurs="1">
                        <xs:element name="catalogItemLink" type="tns:CatalogItemLinkType" />
                        <xs:element name="catalogItem" type="tns:CatalogItemType" />
                    </xs:choice>
                    <!-- Link to the purchase-order-item that caused this purchased-item instance. -->
                    <xs:choice minOccurs="0" maxOccurs="1">
                        <xs:element name="purchaseOrderItemLink" type="tns:PurchaseOrderItemLinkType" />
                        <xs:element name="purchaseOrderItem" type="tns:PurchaseOrderItemType" />
                    </xs:choice>
                    <!-- A link to the user's purchase history root resource. -->
                    <xs:choice minOccurs="0" maxOccurs="1">
                        <xs:element name="purchaseHistoryLink" type="tns:PurchaseHistoryLinkType" />
                        <xs:element name="purchaseHistory" type="tns:PurchaseHistoryType" />
                    </xs:choice>
                    <!-- Link to the parent item, will not appear in case it is an item on level 0. -->
                    <xs:choice minOccurs="0" maxOccurs="1">
                        <xs:element name="parentItemLink" type="tns:PurchasedItemsLinkType" />
                        <xs:element name="parentItem" type="tns:PurchasedItemsType" />
                    </xs:choice>
                    <!-- Links to sub-items that were added afterwards. Can be omitted when there are no sub-items. -->
                    <xs:choice minOccurs="0" maxOccurs="1">
                        <xs:element name="subItemsLink" type="tns:PurchasedItemsLinkType" />
                        <xs:element name="subItems" type="tns:PurchasedItemsType" />
                    </xs:choice>
                    <!-- The price the user has paid for this single item. FIXME: redundant, since available in the purchase order. -->
                    <xs:choice minOccurs="0" maxOccurs="1">
                        <xs:element name="price" type="xs:double" />
                        <xs:element name="priceTag" type="xs:string" />
                    </xs:choice>
                    <!-- The currency used to execute the purchase. -->
                    <xs:element name="currency" type="xs:string" minOccurs="0" maxOccurs="1" />
                    <!-- The user that owns the purchased-item. -->
                    <xs:element name="userId" type="xs:string" minOccurs="0" maxOccurs="1" />
                    <!-- The number of maximum downloads in case the product is downloadable. Zero or omitted otherwise. -->
                    <xs:element name="maxDownloads" type="xs:unsignedByte" minOccurs="0" maxOccurs="1" />
                    <!-- The number of remaining downloads in case the product is downloadable. Zero or omitted otherwise. -->
                    <xs:element name="remainingDownloads" type="xs:unsignedByte" minOccurs="0" maxOccurs="1" />
                    <!-- Flag to indicate if an associated license has expired. Can be omitted if not applicable. -->
                    <xs:element name="isExpired" type="xs:boolean" minOccurs="0" maxOccurs="1" />
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

</xs:schema>
